﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestListGenerator.Tests
{
    /// <summary>
    /// Summary description for TestListGeneratorExceptionTests
    /// </summary>
    [TestClass]
    public class TestListGeneratorExceptionTests
    {
        public TestListGeneratorExceptionTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        public const string EXCEPTION_MESSAGE = "Hello World";


        [TestMethod]
        public void TestConstructor()
        {
            try
            {
                throw new TestListGeneratorException(TestListGeneratorExceptionType.InvalidConfiguration, EXCEPTION_MESSAGE);
            }
            catch (TestListGeneratorException ex)
            {
                Assert.AreEqual(TestListGeneratorExceptionType.InvalidConfiguration, ex.Type, "The type was not set for the exception");
                Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message, "The exception message wasn't set correctly");
            }
        }

        [TestMethod]
        public void TestConstructor_InnerException()
        {
            try
            {
                throw new TestListGeneratorException(TestListGeneratorExceptionType.MissingConfigurationParameter, EXCEPTION_MESSAGE, new TestListGeneratorException(TestListGeneratorExceptionType.TestDLLInvalidFormat, "[Inner] " + EXCEPTION_MESSAGE));
            }
            catch (TestListGeneratorException ex)
            {
                Assert.AreEqual(TestListGeneratorExceptionType.MissingConfigurationParameter, ex.Type, "The type was not set for the exception");
                Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message, "The exception message wasn't set correctly");
                Assert.IsNotNull(ex.InnerException, "The inner exception wasn't set correctly for the exception");
                Assert.AreEqual(TestListGeneratorExceptionType.TestDLLInvalidFormat, ((TestListGeneratorException)ex.InnerException).Type, "The type was not set for the inner exception");
                Assert.AreEqual("[Inner] " + EXCEPTION_MESSAGE, ex.InnerException.Message, "The inner exception message wasn't set correctly");
            }
        }

    }
}
